package com.shop2cn.iapi.prodstockmgr.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.prodstockmgr.parameter.GetTaskListBean;
import com.shop2cn.iapi.prodstockmgr.service.GetTaskListCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.Shop2cnStockCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;

/**
 * 查询任务列表Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetTaskList {
	private static GetTaskListBean gettasklistBean;
	private static GetTaskListCall gettasklistCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询任务列表Test");
	}

	@Before
	public void caseUp() {
		gettasklistBean = new GetTaskListBean();
		gettasklistCall = new GetTaskListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(gettasklistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetTaskList_001() {
		Logger.start(true, "查询导出任务列表,成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchid,
					"", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			Shop2cnStockCallService.AddExportTask(mchid);
			
			gettasklistBean.setSellerId(mchid);
			gettasklistBean.setType(2);
			gettasklistBean.setPageIndex(1);
			gettasklistBean.setPageSize(10);
			gettasklistCall.setData(gettasklistBean);
			gettasklistCall.callService();
			Logger.verifyEquals("200", gettasklistCall.getString("code"), "验证code");
			
			Logger.verifyEquals(1, gettasklistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("taskList").size(), "验证查询到了任务");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetTaskList_002() {
		Logger.start(true, "查询导入任务列表,成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			Shop2cnStockCallService.AddImportTask(mchid);
			Thread.sleep(1000);
			gettasklistBean.setSellerId(mchid);
			gettasklistBean.setType(1);
			gettasklistBean.setPageIndex(1);
			gettasklistBean.setPageSize(10);
			gettasklistCall.setData(gettasklistBean);
			gettasklistCall.callService();
			Logger.verifyEquals("200", gettasklistCall.getString("code"), "验证code");
			Logger.verifyEquals(1, gettasklistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("taskList").size(), "验证查询到了任务");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}